package cn.changein.framework.api.setting.area.controller;

import cn.changein.framework.base.controller.BaseController;
import cn.changein.framework.base.pojo.page.PageInfo;
import cn.changein.framework.kernel.model.response.ErrorResponseData;
import cn.changein.framework.kernel.model.response.SuccessResponseData;
import cn.changein.framework.model.setting.area.model.params.AreaParam;
import cn.changein.framework.model.setting.area.model.result.AreaResult;
import cn.changein.framework.service.setting.area.AreaService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * 地区表控制器
 *

 * @Date 2020-12-15 16:33:48
 * @Copyright: companyName
 * @Version 1.0
 * @Since JDK1.8
 */
@RestController("apiAreaController")
@RequestMapping("/api/area")
public class ApiAreaController extends BaseController {

    @Autowired
    private AreaService areaService;

    /**
     * 查询列表
     *

     * @Date 2020-12-15
     */
    @RequestMapping("/list")
    public PageInfo list(AreaParam areaParam) {
        return this.areaService.findPageBySpec(areaParam);
    }


    /**
     * @Description: 获取省市 区
     * @Date:2020/12/19 15:02
     * @Param: [areaParam]

     */
    @RequestMapping("findByParentId")
    public Object findByParentId(@RequestBody AreaParam areaParam) {
        String parentId = areaParam.getParentId();
        if (StringUtils.isBlank(parentId)) {
            return ErrorResponseData.error("上级Id不能为空!");
        }
        List<AreaResult> list = this.areaService.findByParentId(areaParam);
        return SuccessResponseData.success(list);
    }


}


